package top.mybatisx.sql.core.sql;

import top.mybatisx.sql.core.sql.base.BaseSql;
import top.mybatisx.sql.core.sql.base.SqlStruct;
import top.mybatisx.sql.core.sql.brige.*;

import java.util.logging.Logger;

public interface Sql extends Select, ConditionAndBy, DistinctFrom, HavingOrderBy, JoinConditionAndBy, WhereJoin, On, BaseSql {

    Logger logger = Logger.getLogger("SQL");

    default SqlStruct buildSql() {
        String selectSql = this.buildSelectSql();
        // logger.info("selectSql = " + selectSql);
        String fromSql = this.buildFromSql();
        // logger.info("fromSql = " + fromSql);
        String joinSql = this.buildJoinSql();
        // System.err.println("joinSql = " + joinSql);
        String whereSql = this.buildWhereSql();
        // logger.info("whereSql = " + whereSql);
        String groupBySql = this.buildGroupBySql();
        // logger.info("groupBySql = " + groupBySql);
        String havingSql = this.buildHavingSql();
        String orderBySql = this.buildOrderBySql();
        // logger.info("最终的参数值: valueList = " + valueList);

        StringBuilder sql = new StringBuilder();
        sql.append(selectSql);
        sql.append(fromSql);
        sql.append(joinSql);
        sql.append(whereSql);
        sql.append(groupBySql);
        sql.append(havingSql);
        sql.append(orderBySql);
        sql.append(lastSql);
        logger.info("得到sql-->" + sql.toString());

        return new SqlStruct(sql.toString(), valueList);
    }


}
